﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using Property.Timers;
using Property.Workers;
using System;

namespace Property.Windows.Forms
{
    /// <summary>
    /// Contains words that extend the description 
    /// of the callbacks-based property value loading process.
    /// </summary>
    public static class FunctionWorkerPrototypeExtensionsCallbacksWindowsForms
    {
        /// <summary>
        /// <para>... throwing an exception if getting a new value takes longer than the specified time ...</para>
        /// <para>( ! ) Don't forget to dispose of what you create with this word.</para>
        /// </summary>
        /// <param name="dueTime">Tell me how long I should wait for the value to come.</param>
        /// <param name="testMode">Tell me if I have to ignore this word.</param>
        public static IFunctionWorkerPrototype<T> Timeout<T>(this IFunctionWorkerPrototype<T> source, TimeSpan dueTime, bool testMode = false)
        {
            return testMode ? source : new TimeoutFunctionWorkerDecoratorPrototype<T>(source, new WindowsFormsTimerPrototype(dueTime));
        }

        /// <summary>
        /// <para>... if not overruled by another call in the specified period of time (when) ...</para>
        /// <para>( ! ) Don't forget to dispose of what you create with this word.</para>
        /// </summary>
        /// <param name="dueTime">Tell me how much time I should wait for another 
        /// call before letting this one pass.</param>
        /// <param name="testMode">Tell me if I have to ignore this word.</param>
        public static IReloaderPrototype<T> Delayed<T>(this IFunctionWorkerPrototype<T> source, TimeSpan dueTime, bool testMode = false)
        {
            return source.Each().Delayed(dueTime, testMode);
        }
    }
}
